﻿/*
 * Created by SharpDevelop.
 * User: Jack Brinegar
 * Date: 1/28/2013
 * Time: 3:53 PM
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */
using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using ButternutSkiPatrol;

namespace AdminDesktop.Controls
{
	/// <summary>
	/// Description of ucRoster.
	/// </summary>
	public partial class ucRoster : UserControl
	{
		public ButternutSkiPatrol.DataFile _data;
		AdminDesktop.Controls.ucViewPerson viewPerson = new AdminDesktop.Controls.ucViewPerson();
			
		public ucRoster()
		{
			//
			// The InitializeComponent() call is required for Windows Forms designer support.
			//
			InitializeComponent();
			//this.Dock = DockStyle.Fill;
			// load the person control
			this.splitContainer1.Panel2.Controls.Add(viewPerson);
			this.viewPerson.Visible=false;		
			this.splitContainer1.Panel2.Dock = DockStyle.Fill;
			this.splitContainer1.Panel2.Anchor = AnchorStyles.Top;
			this.splitContainer1.Panel2.Controls[0].Width = this.splitContainer1.Panel2.Width;
			this.splitContainer1.SplitterDistance=175;
			//this.splitContainer1.Panel2.Controls[0].Height = this.splitContainer1.Panel2.Height;
			this.splitContainer1.Panel2.Refresh();	
			LoadData();
		}
		
		private void showPerson()
		{
			this.viewPerson.Visible=true;
		}
		
		public void LoadData()
		{
			this.lvwPatrollers.Items.Clear();
			this.lvwPatrollers.SmallImageList=this.imgList;
			
			if(DataEngine.dataFile.roster!=null)
			{
				for(int i = 0; i < DataEngine.dataFile.roster.Patrollers.Count;i++)
				{
					ListViewItem myItem = this.lvwPatrollers.Items.Add(Utility.TitleCaseString(DataEngine.dataFile.roster.Patrollers[i].LastName) + ", " + Utility.TitleCaseString(DataEngine.dataFile.roster.Patrollers[i].FirstName) );
					myItem.Tag = DataEngine.dataFile.roster.Patrollers[i];
					switch(DataEngine.dataFile.roster.Patrollers[i].Level)
					{
						case "Candidate":
							myItem.ImageIndex=0;
							break;
						case "Non S&T Patroller":
							myItem.ImageIndex=1;
							break;
						case "S&T Patroller":
							myItem.ImageIndex=2;
							break;
						case "Senior":
							myItem.ImageIndex=3;
							break;
						case "Hill Captain":
							myItem.ImageIndex=4;
							break;
						case "Alumni":
							myItem.ImageIndex=5;
							break;
					}
				}
			}
		}
				
		void BtnNewClick(object sender, EventArgs e)
		{
			showPerson();
			this.viewPerson.LoadData(new ButternutSkiPatrol.Person());
			viewPerson.NewPatroller=true;
		}
		
		void LvwPatrollersSelectedIndexChanged(object sender, EventArgs e)
		{
			if (lvwPatrollers.SelectedItems.Count == 1)
			{
				showPerson();
				this.viewPerson.LoadData((ButternutSkiPatrol.Person)this.lvwPatrollers.SelectedItems[0].Tag);
			}
		}
		
		void SplitContainer1SplitterMoved(object sender, SplitterEventArgs e)
		{
			//MessageBox.Show(this.splitContainer1.SplitterDistance.ToString());
		}
	}
}
